package com.dnjn.mes.biz.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.dnjn.mes.biz.enums.AddrCode;
import com.dnjn.mes.common.core.domain.BaseEntity;
import lombok.Getter;
import lombok.Setter;
import org.apache.ibatis.type.CharacterTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.math.BigDecimal;

/**
 * <p>
 * 设备
 * </p>
 *
 * @author Amber
 * @since 2023-07-28
 */
@Getter
@Setter
@TableName(value = "mes_equipment")
public class MesEquipment extends BaseEntity {

    private static final long serialVersionUID = 1L;

    /**
     * PK
     */

    @TableId(value = "equipment_id", type = IdType.ASSIGN_ID)
    private Long equipmentId;

    /**
     * 型号
     */
    private String equipmentNo;

    /**
     * 设备名
     */
    private String equipmentName;

    /**
     * 描述
     */
    private String equipmentDescription;

    private Integer ordinal;


    private String primaryImage;
    /**
     * 默认节拍
     */
    private Integer defaultBeat;

    private String modbusIp;

    private Integer modbusPort;


    /**
     * 运行时长
     */
    private BigDecimal durationRunning;

    /**
     * 停机时长
     */
    private BigDecimal durationStop;

    /**
     * 待机时长
     */
    private BigDecimal durationAwait;

    /**
     * 维修时长
     */
    private BigDecimal durationMaintain;

    /**
     * 是否当前机器
     */
    private String isDefault;

    /**
     * 是否删除|0-否 1-是|valid
     */
    private String deleted;



    public BigDecimal getDurationRunning() {
        return null == durationRunning ? BigDecimal.ZERO : durationRunning;
    }

    public BigDecimal getDurationStop() {
        return null == durationStop ? BigDecimal.ZERO : durationStop;
    }

    public BigDecimal getDurationAwait() {
        return null == durationAwait ? BigDecimal.ZERO : durationAwait;
    }

    public BigDecimal getDurationMaintain() {
        return null == durationMaintain ? BigDecimal.ZERO : durationMaintain;
    }

    public void updateDuration(AddrCode addrCode, BigDecimal durationHour) {
        switch (addrCode) {
            case AWAIT:
                setDurationAwait(getDurationAwait().add(durationHour));//?
                break;
            case STOP:
                setDurationStop(getDurationStop().add(durationHour));
                break;
            case MAINTAIN:
                setDurationMaintain(getDurationMaintain().add(durationHour));
                break;
            case RUNNING:
                setDurationRunning(getDurationRunning().add(durationHour));
            default:
                break;
        }
    }
}
